/**   
 * @Title: CyberPropertyPlaceholderConfigurer.java 
 * @Package com.org.framework 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author cssuger@163.com   
 * @date 2017年1月22日 下午3:19:14 
 * @version V1.0   
 */
package com.bicon.base.data.common;

import java.util.Map;
import java.util.Properties;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import com.google.common.collect.Maps;

/** 
 *@ClassName: CyberPropertyPlaceholderConfigurer 
 *@Description: 对PropertyPlaceholderConfigurer进行扩展，对数据库密码进行加密和解密
 *@author cssuger@163.com 
 *@date 2017年1月22日 下午3:19:14  
 */
public class BiconPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer{

	
	private final Properties newProperties = new Properties();
	
	public void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
			throws BeansException{
		Map<String,String> map = Maps.fromProperties(props);
		newProperties.putAll(map);
		String usename =  map.get("username").trim();
		String pwd = map.get("password").trim();
		try {
//			byte[] userFrom = SecurityUtil.parseHexStr2Byte(usename);  
//			byte[] userResult = SecurityUtil.decrypt(userFrom,SecurityUtil.KEY); 
//			newProperties.put("username", new String(userResult));
			newProperties.put("username", usename);
//			byte[] pwdFrom = SecurityUtil.parseHexStr2Byte(pwd);  
//			byte[] pwdResult = SecurityUtil.decrypt(pwdFrom,SecurityUtil.KEY); 
//			newProperties.put("password", new String(pwdResult));
			newProperties.put("password", pwd);
			
		} catch (Exception e) {
			e.printStackTrace();
		} 
		
		super.processProperties(beanFactory, newProperties);
	}
}
